package tg.app.rj.workticket;

import java.rmi.RemoteException;

import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.mbo.MboValue;
import psdi.util.MXException;
import tg.app.rj.util.CommonUtil;

/***
 * 
 * @author pzx
 *
 */
public class FldWtnum2 extends psdi.mbo.MAXTableDomain {
	
	public FldWtnum2(MboValue mbv) throws MXException {
		super(mbv);
		try {
			String strAttrName = getMboValue().getAttributeName().toUpperCase();
			setRelationship("workticket", " 1=1 ");
			setKeyMap("WORKTICKET", new String[] { strAttrName },new String[] { "WTNUM" });
		} catch (Exception e) {
		}
		/*
		 
		String thisAttr = getMboValue().getAttributeName();
		setRelationship("PERSON", (new StringBuffer()).append("personid=:").append(thisAttr).toString());
		setListCriteria("status in (select value from synonymdomain where maxvalue='ACTIVE' and domainid='PERSONSTATUS')");
		setErrorMessage("person", "InvalidPerson");
		
		*/
	}
	
	
	public MboSetRemote getList() throws MXException, RemoteException {
		return super.getList();
	}
	/*
	public String getLookupName() throws MXException, RemoteException {
		MboValue value = getMboValue();
		MboRemote mbo = value.getMbo();
		if(mbo==null ){
			return "";
		}
		String type = mbo.getString("RANDOM");
		if (type == null || type.equals("") ) {
			return "";
		}
		if ((type != null) && (type.equalsIgnoreCase("Y"))) {
			return "explib";
		}
		if ((type != null) && (type.equalsIgnoreCase("N"))) {
			return "person";
		}
		return super.getLookupName();
	}
	*/
	
	public String[] getAppLink() throws MXException, RemoteException {
		setup();
		MboValue value = getMboValue();
		MboRemote mbo = value.getMbo();
		String type = mbo.getString("WTTYPE");
		if(type!=null){
			if(CommonUtil.D1.equalsIgnoreCase(type)){
				return new String[]{CommonUtil.WTDQ1};
			}else if(CommonUtil.D2.equalsIgnoreCase(type)){
				return new String[]{CommonUtil.WTDQ2};
			}else if(CommonUtil.H1.equalsIgnoreCase(type)){
				return new String[]{CommonUtil.WTDH1};
			}else if(CommonUtil.H2.equalsIgnoreCase(type)){
				return new String[]{CommonUtil.WTDH2};
			}else if(CommonUtil.RJ.equalsIgnoreCase(type)){
				return new String[]{CommonUtil.WTRJ};
			}else if(CommonUtil.RK.equalsIgnoreCase(type)){
				return new String[]{CommonUtil.WTRK};
			}else if(CommonUtil.JD.equalsIgnoreCase(type)){
				return new String[]{CommonUtil.WTJDBH};
			}else if(CommonUtil.YJ.equalsIgnoreCase(type)){
				return new String[]{CommonUtil.WTYJJX};
			}else if(CommonUtil.LX.equalsIgnoreCase(type)){
				return new String[]{CommonUtil.WTACLX};
			}
		}
		return super.getAppLink();
	}
	
	protected void setup() throws MXException, RemoteException {
		MboValue value = getMboValue();
	   if(value!=null && value.getMbo()!=null ){
			try {
				String strAttrName = getMboValue().getAttributeName().toUpperCase();
				setRelationship("WORKTICKET", "1=1");
				value.getMboValueInfo().setSameAsObject("workticket");
				value.getMboValueInfo().setSameAsAttribute("WTNUM");
				setListCriteria(" 1=1 ");
				setKeyMap("WORKTICKET", new String[] { strAttrName },new String[] { "WTNUM" });
				//setLookupKeyMapInOrder(new String[] { "WTNUM" }, new String[] { "WTNUM"});
			} catch (Exception e) {
			}
	   }else {
			setRelationship(null, null);
	   }
	   /*
	    * 
	   
	   	if ((type != null) && (type.equalsIgnoreCase("N"))) {
		  
			setRelationship("person", "1=1");
			
			value.getMboValueInfo().setSameAsObject("PERSON");
			value.getMboValueInfo().setSameAsAttribute("PERSONID");
			setListCriteria(" 1=1");
			setLookupKeyMapInOrder(new String[] { "PERSONID","REMARK" }, new String[] { "PERSONID","DISPLAYNAME"});
		} else if ((type != null) && (type.equalsIgnoreCase("Y"))) {
			
			setRelationship("KTD_EXPLIB", "1=1   ");
			setListCriteria(" 1=1");
			value.getMboValueInfo().setSameAsObject("KTD_EXPLIB");
			 value.getMboValueInfo().setSameAsAttribute("KTD_EXPLIBNUM");
			setLookupKeyMapInOrder(new String[] { "PERSONID", "REMARK" }, new String[] { "KTD_EXPLIBNUM","FULLNAME"});
		} 
	   
	   
	   *
	    */
	
	}
	/*
	public void validate() throws MXException, RemoteException {
		MboValue mbv = getMboValue();
		MboRemote mbo = mbv.getMbo();
	    String type = mbo.getString("RANDOM");
		
		if ((type != null) && (type.equalsIgnoreCase("Y"))) {
	
			setup();
			try {
				super.validate();
			} catch (MXException e) {
			}
		}
		if ((type != null) && (type.equalsIgnoreCase("N"))) {
			setup();
		}
	}
	*/
	public MboSetRemote smartFind(String value, boolean exact) throws MXException, RemoteException {
		if (value.startsWith(":")) {
			return null;
		}
		setup();
	
		return super.smartFind(value, exact);
	}
	
	public MboSetRemote smartFind(String sourceObj, String value, boolean exact) throws MXException, RemoteException {
		if (value.startsWith(":")) {
			return null;
		}
		setup();
		return super.smartFind(sourceObj, value, exact);
	}
	
	public void action() throws MXException, RemoteException {
		super.action();
	}
	
}

